import React,{Component} from 'react'
import './App.css';
import MusicItem from './components/MusicItem'
import axios from 'axios'
export default class App extends Component {
  constructor(props){
    super(props)
    this.state={
      child:"music",
      music:[]
    }
  }
  render(){
    return (
      <div className="App">
        <MusicItem data={this.state.music}></MusicItem>
      </div>
    )
  }
  componentDidMount(){
    axios.get('http://localhost:3000/top/playlist?cat=%E5%8D%8E%E8%AF%AD').then(res=>{
      res.data.playlists.forEach(item=>{
        item.playCount = this.handleCount(item.playCount)
      })
      this.setState({
        music:res.data.playlists
      })
    })
  }
  handleCount(num){
    if(num>100000000){
      return Math.floor(num/100000000)+'亿'
    }else if(num>10000){
      return Math.floor(num/10000)+'万'
    }else{
      return num
    }
  }
}


